<?php
defined('DT_ADMIN') or exit('Access Denied');
include tpl('header');
show_menu($menus);
?>
<form action="?" target="_blank" id="check_title">
    <input type="hidden" name="moduleid" value="<?php echo $moduleid;?>"/>
    <input type="hidden" name="file" value="<?php echo $file;?>"/>
    <input type="hidden" name="kw" value="" id="kw"/>
</form>
<form method="post" action="?" id="dform" onsubmit="return check();">
    <input type="hidden" name="moduleid" value="<?php echo $moduleid;?>"/>
    <input type="hidden" name="file" value="<?php echo $file;?>"/>
    <input type="hidden" name="action" value="<?php echo $action;?>"/>
    <input type="hidden" name="itemid" value="<?php echo $itemid;?>"/>
    <input type="hidden" name="forward" value="<?php echo $forward;?>"/>
    <div class="tt"><?php echo $action == 'add' ? '添加' : '修改';?><?php echo $MOD['name'];?></div>
    <table cellpadding="2" cellspacing="1" class="tb">
        
        <tr>
            <td class="tl"><span class="f_red">*</span> 所属分类</td>
            <td>
                <?php echo $_admin == 1 ? category_select('post[catid]', '选择分类', $catid, $moduleid) : ajax_category_select('post[catid]', '选择分类', $catid, $moduleid);?>&nbsp;&nbsp;
                <!-- //-- commented by ujh  2016.07.22  -- begin -- 
                <input type="checkbox" name="post[islink]" value="1" id="islink" onclick="_islink();" <?php if($islink) echo 'checked';?>/> 外部链接 
                //-- commented by ujh  2016.07.22   -- end -- -->
                <input type="checkbox" name="post[islink]" style="display:none" id="islink" onclick="_islink();" <?php if($islink) echo 'checked';?>/> 
                <span id="dcatid" class="f_red"></span>
            </td>
        </tr>
        <!-- // -- if is zhaobiao then -- begin -- -->
        <?php if( $moduleid == 23 ) { ?>
        <tr>
            <td rowspan="2" class="tl"><span class="f_red">*</span> 行业分类 </td>
            <td>
                <div id="addtags" style="float:left;margin-right:10px"></div>&nbsp;&nbsp;&nbsp;
                <input type="button" style="float:left" value="添加" onclick="addFilterCategory();" class="btn"/>
				<span id="dcategory" class="f_red"></span>
            </td>
        </tr>
        <tr>
            <td>
                <input type='hidden' value='' name='post[tag]' id='tag'>
                <input type="text" style="float:left;background-color:#fafafa;border:solid 1px #aaaaaa;" readonly="true" id="filtercategory" name="post[filtercategory]" size="60" value="<?php echo $filtercategory;?>"></input>
                <input type="button" style="margin-left:10px;float:left" value="清除" onclick="$('#filtercategory').val('');return false;" class="btn"/>                
            </td>
        </tr>        
        <tr>
            <td rowspan="2" class="tl"><span class="f_red">*</span> 所在地区</td>
            <td>
                <?php echo ajax_area_select('post[areaid]', '全部地区', $areaid);?>  
                <input type="button" style="float:left" value="添加" onclick="addDistrict();" class="btn"/>
				<span id="dareaid" class="f_red"></span>
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" style="float:left;background-color:#fafafa;border:solid 1px #aaaaaa;" id="filteraddress" name="post[filteraddress]" size="60" readonly="true" value="<?php echo $filteraddress;?>"></input>
                <input type="button" style="margin-left:10px;float:left" value="清除" onclick="$('#filteraddress').val('');return false;" class="btn"/>                
            </td>
        </tr>
        <?php } ?>
        <!-- // -- if is zhaobiao then -- end -- -->
        
        <tr>
            <td class="tl"><span class="f_red">*</span> <?php echo $MOD['name'];?>标题</td>
            <td>
                    <input name="post[title]" type="text" id="title" size="60" value="<?php echo $title;?>"/> <?php echo level_select('post[level]', '级别', $level, 'id="level"');?>
                    <?php echo dstyle('post[style]', $style);?>&nbsp;&nbsp;
                    <input type="button" value="标题检测" onclick="check_title();" class="btn"/><br/>
                    <span id="dtitle" class="f_red"></span>
            </td>
        </tr>
        <tr>
            <td class="tl"><span class="f_hid">*</span> 标题图片</td>
            <td>
                <input name="post[thumb]" id="thumb" type="text" size="60" value="<?php echo $thumb;?>"/>&nbsp;&nbsp;
                <span onclick="Dthumb(<?php echo $moduleid;?>,Dd('level').value==2 ? 330 : <?php echo $MOD['thumb_width'];?>,Dd('level').value==2 ? 250 : <?php echo $MOD['thumb_height'];?>, Dd('thumb').value);" class="jt">[上传]</span>&nbsp;&nbsp;
                <span onclick="_preview(Dd('thumb').value);" class="jt">[预览]</span>&nbsp;&nbsp;
                <span onclick="Dd('thumb').value='';" class="jt">[删除]</span>
            </td>
        </tr>
        
        
        <?php echo $FD ? fields_html('<td class="tl">', '<td>', $item) : '';?>
        <tr>
            <td class="tl"><span class="f_red">*</span> <?php echo $MOD['name'];?>内容</td>
            <td><textarea name="post[content]" id="content" class="dsn"><?php echo $content;?></textarea>
                <?php echo deditor($moduleid, 'content', $MOD['editor'], '100%', 350);?><br/><span id="dcontent" class="f_red"></span>
            </td>
        </tr>
        
        <!-- //-- commented by ujh  2016.07.22  -- begin -- 
        <?php
        if($MOD['swfu'] && DT_EDITOR == 'fckeditor') { 
                include DT_ROOT.'/api/swfupload/editor.inc.php';
        }
        ?>
        <tr>
            <td class="tl" height="30"><span class="f_hid">*</span> 内容选项</td>
            <td>
                <a href="javascript:pagebreak();Ds('subtitle');"><img src="admin/image/pagebreak.gif" align="absmiddle"/> 插入分页符</a>&nbsp;&nbsp;
                <input type="checkbox" name="post[save_remotepic]" value="1"<?php if($MOD['save_remotepic']) echo 'checked';?>/>下载远程图片&nbsp;&nbsp;
                <input type="checkbox" name="post[clear_link]" value="1"<?php if($MOD['clear_link']) echo 'checked';?>/>清除链接&nbsp;&nbsp;
                截取内容 <input name="post[introduce_length]" type="text" size="2" value="<?php echo $MOD['introduce_length']?>"/> 字符至简介&nbsp;&nbsp;
                设置内容第 <input name="post[thumb_no]" type="text" size="2" value=""/> 张图片为标题图
            </td>
        </tr>
        <tbody id="subtitle" style="display:<?php echo $pagebreak ? '' : 'none';?>;">
            <tr>
                <td class="tl"><span class="f_hid">*</span> 分页标题</td>
                <td>
                    <textarea name="post[subtitle]" style="width:90%;height:45px;"><?php echo $subtitle;?></textarea>
                    <br/>1行一个分页标题，按回车换行
                </td>
            </tr>
        </tbody>
        //-- commented by ujh  2016.07.22  -- end --  -->
        
        <!-- // -- if is zhaobiao then -- begin -- -->
        <?php if( $moduleid == 23 ) { ?>
        <tr>
            <td class="tl"><span class="f_hid">*</span> <?php echo $MOD['name'];?>简介</td>
            <td><textarea name="post[introduce]" style="width:99%;height:45px;"><?php echo $introduce;?></textarea></td>
        </tr>
        <tr height="30">
            <td class="tl"><span class="f_hid">*</span> <?php echo $MOD['name'];?>作者</td>
            <td><input type="text" size="10" name="post[author]" value="<?php echo $author;?>" id="author"/> <img src="<?php echo $MODULE[2]['linkurl'];?>image/img_select.gif" width="12" height="12" title="选择常用作者" class="c_p" onclick="TopUse('author');"/>&nbsp;&nbsp;<?php echo $MOD['name'];?>来源 <input type="text" size="12" name="post[copyfrom]" value="<?php echo $copyfrom;?>" id="copyfrom"/>&nbsp;&nbsp;来源链接 <input type="text" size="25" name="post[fromurl]" value="<?php echo $fromurl;?>" id="fromurl"/> <img src="<?php echo $MODULE[2]['linkurl'];?>image/img_select.gif" width="12" height="12" title="选择常用来源" class="c_p" onclick="TopUse('from');"/></td>
        </tr>
        <!-- 
        <tr>
            <td class="tl"><span class="f_hid">*</span> 插入投票</td>
            <td><input name="post[voteid]" type="text" size="10" value="<?php echo $voteid;?>"/><?php tips('请填写投票ID，多个ID请用空格隔开');?></td>
        </tr>
        -->
        <tr>
            <td class="tl"><span class="f_hid">*</span> <?php echo $MOD['name'];?>状态</td>
            <td>
                <input type="radio" name="post[status]" value="3" <?php if($status == 3) echo 'checked';?> id="status_3"/><label for="status_3"> 通过</label>
                <input type="radio" name="post[status]" value="2" <?php if($status == 2) echo 'checked';?> id="status_2"/><label for="status_2">  待审</label>
                <!-- //-- commented by ujh  2016.07.22  
                <input type="radio" name="post[status]" value="1" <?php if($status == 1) echo 'checked';?> onclick="if(this.checked) Dd('note').style.display='';" id="status_1"/><label for="status_1">  拒绝</label>
                -->
                <input type="radio" name="post[status]" value="0" <?php if($status == 0) echo 'checked';?> id="status_0"/><label for="status_0">  删除</label>
            </td>
        </tr>
        <tr id="note" style="display:<?php echo $status==1 ? '' : 'none';?>">
            <td class="tl"><span class="f_red">*</span> 拒绝理由</td>
            <td><input name="post[note]" type="text"  size="40" value="<?php echo $note;?>"/></td>
        </tr>
        <tr>
            <td class="tl"><span class="f_hid">*</span> 浏览次数</td>
            <td><input name="post[hits]" style="min-width:120px" type="text" size="10" value="<?php echo $hits;?>"/></td>
        </tr>
        <tr>
            <td class="tl"><span class="f_hid">*</span> 添加时间</td>
            <td><input type="text" size="22" name="post[addtime]" value="<?php echo $addtime;?>"/></td>
        </tr>
       
        
        <!-- // commented by ujh  2016.07.22
        <tr>
            <td class="tl"><span class="f_hid">*</span> 内容收费</td>
            <td><input name="post[fee]" type="text" size="5" value="<?php echo $fee;?>"/><?php tips('不填或填0表示继承模块设置价格，-1表示不收费<br/>大于0的数字表示具体收费价格');?>
        </td>
        </tr>        
        <tr>
            <td class="tl"><span class="f_hid">*</span> 内容模板</td>
            <td><?php echo tpl_select('show', $module, 'post[template]', '默认模板', $template, 'id="template"');?><?php tips('如果没有特殊需要，一般不需要选择<br/>系统会自动继承分类或模块设置');?></td>
        </tr>
        -->
        <?php if($MOD['show_html']) { ?>
        <tr>
            <td class="tl"><span class="f_hid">*</span> 自定义文件路径</td>
            <td><input type="text" size="50" name="post[filepath]" value="<?php echo $filepath;?>" id="filepath"/>&nbsp;<input type="button" value="重名检测" onclick="ckpath(<?php echo $moduleid;?>, <?php echo $itemid;?>);" class="btn"/>&nbsp;<?php tips('可以包含目录和文件 例如 destoon/b2b.html<br/>请确保目录和文件名合法且可写入，否则可能生成失败');?>&nbsp; <span id="dfilepath" class="f_red"></span></td>
        </tr>
        <?php } ?>
        
        <tr style="display: none">
            <td class="tl"><span class="f_red">*</span> 招标编号</td>
            <td>
                <input type="text" size="50" name="post[zp_number]" value="<?php echo $catid;?>" id="zp_number"/>&nbsp;<?php tips('可以包含目录和文件 例如 destoon/b2b.html<br/>请确保目录和文件名合法且可写入，否则可能生成失败');?>&nbsp; <span id="dfilepath" class="f_red"></span>
            </td>
        </tr>
        
        <tr style="display:none">
            <td class="tl"><span class="f_red">*</span> 标讯类别</td>
            <td>
                <select name="zp_type" id="zp_type" onchange="selectType();"> 
                    <!-- <option value="0" >招标</option>
                    -->
                    <option value="1" >公告</option>
                </select>
                   
            </td><span id="dfilepath" class="f_red"></span></td>
        </tr> 
       
        <tr>
            <td class="tl">
                <input type="button" style="float:left;height:30px;background:#24a2e0;color:white;cursor:pointer;" value="获取招标信息" onclick="getInfomation();"  />
            </td>
            <td>
                <table id="zp_additional_item">
                    <tr>
                        <td class="tl" style="width:250px">
                            <div style="float:left;width:80px"> 招标编码 </div><input type="text" size="20" name="post[zp_source]" value="" id="zp_source"/>                            
                        </td>
                        <td style="width:20px">
                        </td>
                        <td class="tl" style="width:250px">
                            <div style="float:left;width:80px"> 招标人 </div><input type="text" size="20" name="post[zp_user1]" value="" id="zp_user1"/>
                        </td>
                    </tr>
                    <tr>
                        <td class="tl" style="width:250px">
                            <div style="float:left;width:80px"> 开标时间 </div><input type="text" size="20" name="post[zp_starttime]" value="<?php echo $starttime;?>" id="zp_starttime"/>
                        </td>
                        <td style="width:20px">
                        </td>
                        <td class="tl" style="width:250px">
                            <div style="float:left;width:80px"> 招标代理 </div><input type="text" size="20" name="post[zp_user2]" value="" id="zp_user2"/>
                        </td>
                    </tr>
                </table> 
            </td>
        </tr>
        <?php } ?>
        <!-- // -- if is zhaobiao then -- end -- -->
        
    </table>
    <div class="sbt"><input type="submit" name="submit" value=" 确 定 " class="btn"/>&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value=" 重 置 " class="btn"/></div>
</form>
<?php load('clear.js'); ?>

<!--  // commented by ujh  2016.07.22
<?php if($action == 'add') { ?>
<form method="post" action="?">
    <input type="hidden" name="moduleid" value="<?php echo $moduleid;?>"/>
    <input type="hidden" name="file" value="<?php echo $file;?>"/>
    <input type="hidden" name="action" value="<?php echo $action;?>"/>
    <input type="hidden" name="catid" value="<?php echo $catid;?>"/>
    <div class="tt">单页采编</div>
    <table cellpadding="2" cellspacing="1" class="tb">
        <tr>
            <td class="tl"><span class="f_hid">*</span> 目标网址</td>
            <td><input name="url" type="text" size="80" value="<?php echo $url;?>"/>&nbsp;&nbsp;<input type="submit" value=" 获 取 " class="btn"/>&nbsp;&nbsp;<input type="button" value=" 管理规则 " class="btn" onclick="Dwidget('?file=fetch', '管理规则');"/></td>
        </tr>
    </table>
</form>
<?php } ?>
-->




<script type="text/javascript">
function check_title() {
	if(Dd('title').value.length < 2) {
		alert('请填写标题');
	} else {
		Dd('kw').value = Dd('title').value;
		Dd('check_title').submit();
	}
}
function TopUse(a) {
	mkDialog('', '<iframe src="?moduleid=<?php echo $moduleid;?>&action='+a+'" width="650" height=250" border="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" framespacing="0" frameborder="0" scrolling="yes"></iframe>', '请选择', 675, 0, 0);
}

function selectType(){
    if($('#zp_type').val() == 1){
        $('#zp_additional_item').css('display', 'none');
           
    }
    else{
         $('#zp_additional_item').css('display', '');
    }
        
}

function check() {
	var l;
	var f;
        
        f = 'title';
	l = Dd(f).value.length;
	if(l < 2) {
		Dmsg('标题最少2字，当前已输入'+l+'字', f);
		return false;
	}
        
        
        
        
	if(Dd('islink').checked) {
            f = 'linkurl';
            l = Dd(f).value.length;
            if(l < 12) {
                Dmsg('请输入正确的链接地址', f);
                return false;
            }
	} else {
            f = 'content';
            l = FCKLen();
            if(l < 5) {
                    Dmsg('内容最少5字，当前已输入'+l+'字', f);
                    return false;
            }
	}
        
        <?php if( $moduleid == 23 ) { ?>
        f = 'catid_1';
		if(Dd(f).value == 0) {
			Dmsg('请选择所属分类', 'catid', 1);
			return false;
		}
		f = 'category_lg';
		if(Dd(f).value == 0 && ($('#filtercategory').val()).length <1) {
			Dmsg('请选择所行业分类', 'category',1);
			return false;
		}
		f = 'area_0';
		if(Dd(f).value == 0 && ($('#filteraddress').val()).length <1) {
			Dmsg('请选择所在地区', 'areaid',1);
			return false;
		}
		
        f = 'zp_type';
        l = Dd(f).value;       
        if(l == 0){                    
            if(Dd('zp_user1').value.length == 0){
                var f1 = 'zp_user1';
                Dmsg('请输入正确的招标人', f1);                
                return false;
            }     
                     
            if(Dd('zp_source').value.length == 0){
                Dmsg('请输入正确的招标编码', 'zp_source');
                return false;
            }
            
            if(Dd('zp_user2').value.length == 0){
                Dmsg('请输入正确的招标代理', 'zp_user2');
                return false;
            }    
        }
        <?php } ?>
       
	<?php echo $FD ? fields_js() : '';?>
	<?php echo $CP ? property_js() : '';?>
	return true;
}

$(function(){
    $.post(AJPath, 'action=tag', function(data) {
           $("#addtags").html(data);  
      });
    
} )
function load_areas(obj){
     $.post(AJPath, 'type=2&action=tag&area_title='+obj, function(data) {
           $("#addtags").html(data);  
      });
}
function load_areas2(obj){
    var val = $("#tag").val();  
    $("#tag").val(val+',(' + obj + ')');
}

function addFilterCategory()
{
    var category_lg = $("#category_lg").val();
    var category_sm = $("#category_sm").val();
    
    var categoryId = 0;
    var categoryText = "";
    if( category_lg != 0  )
    {
        categoryId = category_lg;
        categoryText = $("#category_lg").find("option:selected").text();
    }
    
    if( category_sm != 0 && isNaN(category_sm) == false )
    {
        categoryId = category_sm;
        categoryText = $("#category_sm").find("option:selected").text();
    }
    
    var itemText =  categoryText + "(" + categoryId + ")";
    
    if( categoryId == 0 )
    {
        itemText = '全部(0)';
        $('#filtercategory').val( itemText );
    }
    var filterValue = $('#filtercategory').val();
    
    if( filterValue.indexOf(itemText) < 0)
    {
        if( filterValue == '')
        {
            $('#filtercategory').val( itemText );
        }
        else
        {
            $('#filtercategory').val( filterValue + ", " +  itemText );
        }
    }
    
}


function addDistrict()
{
    var area_lg = $("#area_0").val();
    var area_sm = $("#area_1").val();
    
    var areaId = 0;
    var areaText = "";
    if( area_lg != 0  )
    {
        areaId = area_lg;
        areaText = $("#area_0").find("option:selected").text();
    }
    
    if( area_sm != 0 && isNaN(area_sm) == false )
    {
        areaId = area_sm;
        areaText = $("#area_1").find("option:selected").text();
    }
    
    var itemText =  areaText + "(" + areaId + ")";    
    if( areaId == 0 )
    {
        itemText = '全部地区(0)';
        $('#filteraddress').val( itemText );
    }
    
    var filterValue = $('#filteraddress').val();
    
    if( filterValue.indexOf(itemText) < 0)
    {
        if( filterValue == '')
        {
            $('#filteraddress').val( itemText );
        }
        else
        {
            $('#filteraddress').val( filterValue + ", " +  itemText );
        }
    }
    
}

function getSearchArrayString(vSubject, vArray )
{
    var iSearch = null;
    var i = 0;
    for( i = 0; i < vArray.length; i++ )
    {
        //iSearch = vSubject.indexOf(vArray[i]);
        var regex = new RegExp(vArray[i]);
        iSearch = vSubject.match(regex);
        if( iSearch != null && iSearch.length > 0 )
            return iSearch;
    }
    return null;
}


function htmlEncode(value){
  //create a in-memory div, set it's inner text(which jQuery automatically encodes)
  //then grab the encoded contents back out.  The div never exists on the page.
  return $('<div/>').text(value).html();
}

function htmlDecode(value){
  return $('<div/>').html(value).text();
}

function getInfomation()
{
    debugger;
    var zp_source = '';
    var zp_starttime = '';
    var zp_user1 = '';
    var zp_user2 = '';
   
    var htmltext = FCKXHTML();    
    var length = FCKLen();
    
    var line_regex = new RegExp("(.*</p>|.*/>)", "g");
    
    // zp_number
    var number_regex = new RegExp("[0-9a-zA-Z\\-]+" );
    var zp_sourceKey = new Array();
    zp_sourceKey[0] = "招\\s*标\\s*编\\s*码\\s*[:|：|\\s|\\-]+";
    zp_sourceKey[1] = "招\\s*标\\s*编\\s*号\\s*[:|：|\\s|\\-]+";
    zp_sourceKey[2] = "项\\s*目\\s*编\\s*号\\s*[:|：|\\s|\\-]+";
    zp_sourceKey[3] = "项\\s*目\\s*编\\s*码\\s*[:|：|\\s|\\-]+";
    
    // zp_starttime
    var starttime_regex = new RegExp("[0-9]+年[0-9]+月[0-9]+日|[0-9]+/[0-9]+/[0-9]+|[0-9]+\\-[0-9]+\\-[0-9]+" );
    var zp_starttimeKey = new Array();
    zp_starttimeKey[0] = "日\\s*期\\s*[:|：|\\s|\\-]+";
    
    // zp_user1
    var user1_regex = new RegExp("\\S+" );
    var zp_user1Key = new Array();
    zp_user1Key[0] = "招\\s*标\\s*人\\s*[:|：|\\s|\\-]+";
    
    // zp_user2
    var user2_regex = new RegExp("\\S+" );
    var zp_user2Key = new Array();
    zp_user2Key[0] = "招标代理\\S*[:|：|\\s|\\-]+";
    
    var result = htmltext.match(line_regex); 
    if (result != null) 
    { 
        var i = 0; 
        
        var iFirst = null;
        var line = '';
        for( i = 0; i < result.length; i++  )
        {
            line = htmlDecode(result[i]);
            
            iFirst = getSearchArrayString(line, zp_sourceKey);            
            if( iFirst != null )
            {
                var numbers = line.match(number_regex);
                if( numbers != null && numbers.length > 0 )
                {
                    zp_source = numbers[0];
                }
            }
            
            iFirst = getSearchArrayString(line, zp_starttimeKey);            
            if( iFirst != null )
            {
                var starttime = line.match(starttime_regex);
                if( starttime != null && starttime.length > 0 )
                {
                    zp_starttime = starttime[0];
                }
            }
            
            iFirst = getSearchArrayString(line, zp_user1Key);            
            if( iFirst != null )
            {
                var matchText = iFirst[0];
                var matchPos  = iFirst['index'];
                var subText = line.substr(matchPos + matchText.length);
                var user1 = subText.match(user1_regex);
                if( user1 != null && user1.length > 0 )
                {
                    zp_user1 = user1[0];
                }
            }
            
            iFirst = getSearchArrayString(line, zp_user2Key);            
            if( iFirst != null )
            {
                var matchText = iFirst[0];
                var matchPos  = iFirst['index'];
                var subText = line.substr(matchPos + matchText.length);
                var user2 = subText.match(user2_regex);
                if( user2 != null && user2.length > 0 )
                {
                    zp_user2 = user2[0];
                }
            }
        }
    }
    
    $('#zp_source').val(zp_source);
    $('#zp_starttime').val(zp_starttime);
    $('#zp_user1').val(zp_user1);
    $('#zp_user2').val(zp_user2);
}

</script>
<script type="text/javascript">Menuon(<?php echo $menuid;?>);</script>
<?php include tpl('footer');?>